<?php


require_once('BaseTransactionReportForm.class.php');
class UnclosedTransactionForm extends BaseTransactionReportForm
{

    public function getOrderByFields(){
        return array(

          EmployeePeer::CODE           => 'employee code'
        , EmployeeI18nPeer::FIRST_NAME => 'name'
        , EmployeePeer::CARD_ID        => 'card id '
        );
    }


    public $display_fields = array(
    'serial'=>'Serial'
    ,'employee_code'=>'Employee Code'
    ,'employee_name'=>'Employee name'
    ,'code_leave_type'=>'Unclosed transaction'
    ,'transaction_function'=>'Transaction function'
    ,'time_out'=>'Time Out'
    ,'time_in'=>'Time in'
    );

    public static $unclosed_transaction_types = array(
    globals::NO_CLOSEING_LEAVE_START => "Unclosed TimeOut"
    , globals::NO_CLOSEING_LEAVE_END  => "Unclosed TimeIn"
    , 'all' => "All"
    );


    public function configure(){
        parent::configure();

        $this->widgetSchema['group_by']= new sfWidgetFormChoice(
        array(
        'expanded' => true,
        'choices'  => $this->getGroupByFields()));
        $this->validatorSchema['group_by']= new sfValidatorChoice(
        array(
        'choices'  => array_keys($this->getGroupByFields()),'required'=>false
        ));

        $this->widgetSchema['unclosed_transaction_type']= new sfWidgetFormChoice(
        array(
        'expanded' => true,
        'choices'  => self::$unclosed_transaction_types));
        $this->validatorSchema['unclosed_transaction_type']= new sfValidatorChoice(
        array(
        'choices'  => array_keys( self::$unclosed_transaction_types),'required'=>false
        ));


        $this->widgetSchema['card_id'] =  new sfWidgetFormInput();
        $this->validatorSchema['card_id'] =  new sfValidatorString(array('required'=>false));

        $this->getWidgetSchema()->setLabel('leave_type_id','Unclosed Transaction');
        $this->getWidgetSchema()->setLabel('unclosed_transaction_type','Show');

        $this->getWidgetSchema()->moveField('card_id','after','employee_id');
        $this->getWidgetSchema()->moveField('section_id','before','employee_id');
        $this->getWidgetSchema()->moveField('department_id','before','section_id');
        $this->getWidgetSchema()->setDefault('unclosed_transaction_type','all');
        $this->getWidgetSchema()->setDefault('group_by','all');

        unset($this['leave_start'],$this['leave_end']);

    }


    protected function addUnclosedTransactionTypeColumnCriteria(Criteria $criteria, $field, $value=null){
        if($value !== null && $value!='all' ){
            $criteria->add(TransactionPeer::TRANSACTION_TYPE , $value );
        }

    }




}
